package org.study.data.migration.boot.controller;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.study.data.migration.boot.dto.DataMigrationDTO;
import org.study.data.migration.boot.service.DataService;

/**
 * 数据迁移接口
 *
 * @author doveylovey
 * @version v1.0.0
 * @email 1135782208@qq.com
 * @date 2025年03月04日
 */
@Slf4j
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
@RestController
@RequestMapping("/data/migration")
public class DataController {
    private final DataService dataService;

    /**
     * 数据迁移
     */
    @PostMapping("/test")
    public Boolean dataMigration(@Validated @RequestBody DataMigrationDTO dataMigrationDTO) {
        String sourceTableName = dataMigrationDTO.getSourceTableName();
        String targetTableName = dataMigrationDTO.getTargetTableName();
        if (StringUtils.isBlank(targetTableName)) {
            targetTableName = sourceTableName;
        }
        return dataService.dataMigration(sourceTableName, targetTableName);
    }
}
